package com.estar.integaration.strategy;

import com.estar.integaration.entity.paymentPlanEntity.DueReceiptDetail;
import com.estar.integaration.entity.paymentPlanEntity.PurchaseOrderDetail;
import lombok.AllArgsConstructor;

import java.util.List;
import java.util.Map;

/**
 * Author: YJL
 * Date: 2022/2/18 15:45
 * 未付全款-已入库-已到票 NYY
 **/
@AllArgsConstructor
public class StrategyNYY extends Strategy {

  /**构造函数注入数值**/
  //应付单号
  String dueNumber = "";
  //应付单列表
  Map<String,DueReceiptDetail> dueReceiptDetailMap = null;


  /**
   * 设置时间和应付的钱
   * @param purchaseOrderDetailList
   * @param purchaseOrderDetail
   * @return
   */
  @Override
  public Boolean setExpectDate(List<PurchaseOrderDetail> purchaseOrderDetailList,PurchaseOrderDetail purchaseOrderDetail,String type) {
      DueReceiptDetail dueReceiptDetail = dueReceiptDetailMap.get(dueNumber);
      if(dueReceiptDetail != null){
        //应付单列表里找到值了,全部按照dueNumber的设置
        for(PurchaseOrderDetail p : purchaseOrderDetailList){
          //是null的按照原List内的来，不是null的按照物料他本身的dueNumber来
          if(! dueNumber.equals(p.getDueNumber())&& p.getDueNumber()!=null){//不等于且不为空
            DueReceiptDetail tmpDueReceiptDetail = dueReceiptDetailMap.get(p.getDueNumber());
            if(tmpDueReceiptDetail != null){//此物料的dueNumber能找到到期日
              p.setExpectPayDate(tmpDueReceiptDetail.getExpireDate());
            }else {//如果是空的那么还是按照原List的来
              p.setExpectPayDate(dueReceiptDetail.getExpireDate());
            }
            p.setNeedPayAmount(p.getAmountDue());
            p.setType(type);
            p.setIfSpecial(false);
            //接着下一个
            continue;
          }
          p.setExpectPayDate(dueReceiptDetail.getExpireDate());
          p.setNeedPayAmount(p.getAmountDue());
          p.setType(type);
          p.setIfSpecial(false);
        }
//        purchaseOrderDetailList.forEach( p ->{
//          p.setExpectPayDate(dueReceiptDetail.getExpireDate());
//          p.setNeedPayAmount(p.getAmountDue());
//          p.setType(type);
//          p.setIfSpecial(false);
//        });//多个全部设置
        return true;
      }else {
        purchaseOrderDetail.setExpectPayDate("应付单号中找不到此单据编号");
        purchaseOrderDetailList.forEach(pod->{
          pod.setIfSpecial(false);
        });
        return false;
      }
  }

}
